﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using CommunityServer.WebServices.Membership;
using CommunityServer.Services;

namespace NENAData.TCAPI
{
    public class User
    {

        public static void UpdateUser(string name, string email)
        {
            try
            {
                var postUrl = "http://nena.ca/"; // or .json
                MembershipService _service = new MembershipService(postUrl, name, "swfaiumrtm75gvwq14");

                CommunityServer.WebServices.Membership.User user = _service.GetUser(name);
                //user.PrivateEmail = email;
                user.PublicEmail = email;
                user.Update();
            }
            catch (Exception)
            {

            }



            //var webClient = new WebClient();

            //// replace the "admin" and "Admin's API key" with your valid user and apikey!
            //// http://telligent.com/community/developers/w/wiki/how-to-generate-an-api-key.aspx
            //var adminKey = String.Format("{0}:{1}", "admin-key", "swfaiumrtm75gvwq14");
            //var adminKeyBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(adminKey));

            //webClient.Headers.Add("Rest-User-Token", adminKeyBase64);
            //webClient.Headers.Add("Rest-Method", "PUT");


            //var data = "<Request><PrivateEmail>" + email + "</PrivateEmail><PublicEmail>" + email + "</PublicEmail></Request>";

            //byte[] a = webClient.UploadData(postUrl, "POST", Encoding.ASCII.GetBytes(data));

        }
    }
}
